﻿using System;
using System.Collections.Generic;

namespace Absky.Cache.Interface
{
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICache
    {
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <param name="value">缓存值</param>
        /// <param name="expireTime">过期时间</param>
        /// <returns></returns>
        bool SetCache<T>(string key, T value, DateTime? expireTime = null);
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <returns></returns>
        T GetCache<T>(string key);
        /// <summary>
        /// 移除缓存
        /// </summary>
        /// <param name="key">缓存名称</param>
        /// <returns></returns>
        bool RemoveCache(string key);

        #region Hash
        /// <summary>
        /// 设置哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <param name="fieldKey">字段名</param>
        /// <param name="fieldValue">字段值</param>
        /// <returns></returns>
        int SetHashFieldCache<T>(string key, string fieldKey, T fieldValue);
        /// <summary>
        /// 设置哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <param name="dict">缓存值，键值对字典</param>
        /// <returns></returns>
        int SetHashFieldCache<T>(string key, Dictionary<string, T> dict);
        /// <summary>
        /// 获取哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <param name="fieldKey">字段名称</param>
        /// <returns></returns>
        T GetHashFieldCache<T>(string key, string fieldKey);
        /// <summary>
        /// 获取哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <param name="dict">Dictionary</param>
        /// <returns></returns>
        Dictionary<string, T> GetHashFieldCache<T>(string key, Dictionary<string, T> dict);
        /// <summary>
        /// 获取哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <returns></returns>
        Dictionary<string, T> GetHashCache<T>(string key);
        /// <summary>
        /// 获取哈希缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存名称</param>
        /// <returns></returns>
        List<T> GetHashToListCache<T>(string key);
        /// <summary>
        /// 移除哈希缓存
        /// </summary>
        /// <param name="key">缓存名称</param>
        /// <param name="fieldKey">字段名称</param>
        /// <returns></returns>
        bool RemoveHashFieldCache(string key, string fieldKey);
        /// <summary>
        /// 移除哈希缓存
        /// </summary>
        /// <param name="key">缓存名称</param>
        /// <param name="dict">缓存字段Dictionary</param>
        /// <returns></returns>
        Dictionary<string, bool> RemoveHashFieldCache(string key, Dictionary<string, bool> dict);
        #endregion
    }
}
